package io.github.xyzboom.cj.data

import io.github.xyzboom.cj.decl.CjVariable
import io.github.xyzboom.cj.decl.evaluateName
import io.github.xyzboom.cj.decl.name
import io.github.xyzboom.cj.decl.qualifyName
import io.github.xyzboom.cj.decl.type
import io.github.xyzboom.cj.decl.value
import io.github.xyzboom.cj.decl.variablesReference

open class DebugVariable(val variable: CjVariable) : IDebugVariable {
    override val id: VarId get() = VarId(variable.variablesReference)
    override val variablesReference: Int get() = variable.variablesReference
    override val qualifyName: String get() = variable.qualifyName
    override val name: String get() = variable.name
    override val type: String get() = variable.type
    override val value: String get() = variable.value
    override val evaluateName: String get() = variable.evaluateName

    val childrenIds = mutableSetOf<VarId>()
    val isLeaf get() = childrenIds.isEmpty()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is DebugVariable) return false

        if (id != other.id) return false

        return true
    }

    override fun hashCode(): Int {
        return id.value.hashCode()
    }

    override fun toString(): String {
        return JSON.stringify(variable) + ", " + childrenIds.toString()
    }
}